#ifndef _LIBTIMER_H_
#define _LIBTIMER_H_

#ifdef __cplusplus
extern "C" {
#endif /** cplusplus **/

#include "libutil.h"
#include "llist.h"

#define USEC_PER_SEC 1000000
#define GET_TIME(x) gettimeofday (&x, NULL)

typedef struct _ptimer_t
{
  struct timeval start;
  struct timeval end;
  unsigned int active;
} ptimer_t;

/* Create new timer */
ptimer_t *new_timer (void);
/* Delete timer */
void destroy_timer (ptimer_t *timer);
/* Begin counter */
void timer_start (ptimer_t *timer);
/* Stop counter */
void timer_stop (ptimer_t *timer);
/* Reset counter */
void timer_reset (ptimer_t *timer);
/* Continue counter */
void timer_continue (ptimer_t *timer);
/* Get elapsed count */
double timer_elapsed (ptimer_t *timer);

/* Delete a double value */
void delete_time (void *data);

/* Calculate the mean of a link list of doubles */
double calculate_avg (double* times,int n);
/* Calculate the standard deviation of a link list of doubles */
double calculate_stddev (double* times,int n);

#ifdef __cplusplus
}
#endif /** cplusplus **/

#endif /** _LIBTIMER_H_ **/

